home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / GENetReleaseƒ / GELibHeaders / Defs.h next >
Text File  |  1994-03-09  |  7KB  |  216 lines

  1. /*
  2.     Defs.h
  3.     
  4.     Type definitions for Graphic Elements release version 1.0b1
  5.     
  6.     Copyright 1994 by Al Evans. All rights reserved.
  7.     
  8.     
  9. */
  10.  
  11. #ifndef GEDEFS
  12. #define GEDEFS
  13.  
  14. //Get Toolbox symbols if we're compiling in MPW
  15. #ifdef applec
  16. #ifndef __cplusplus
  17. #ifndef PRELOAD
  18. #pragma load "::ToolKit.precompile"
  19. #define PRELOAD
  20. #endif
  21. #endif
  22. #else
  23. #include <QDOffscreen.h>
  24. #endif
  25.  
  26. #include "List.h"
  27.  
  28. //All offscreen graphics are 8 bits deep
  29. #define    offscrnDepth    8
  30.  
  31. //Some forward declarations
  32. typedef struct GrafElement* GrafElPtr;
  33. typedef struct GEWorld* GEWorldPtr;
  34.  
  35. //Built-in directions
  36. typedef enum {none, up, left, down, right, upLeft, upRight, downLeft, downRight} GEDirection;
  37.  
  38. /* 
  39.     Prototype of function to initialize a graphic element from a resource or series
  40.     of resources. This function is responsible for creating an offscreen GWorld
  41.     for the element if required, and rendering the resource(s) into it.
  42.     
  43.     This function is responsible for setting the fields element->resID, element->graphRect,
  44.     and element->graphWorld.
  45. */
  46.  
  47. typedef pascal Boolean (*GraphicLoadFunc) (GEWorldPtr world, GrafElPtr element,
  48.                             short startResNum, short nResources);
  49.  
  50. /*
  51.     Prototype for general-purpose bit copy function type-compatible with CopyBits.
  52.     BitCopyProcs are normally used for offscreen-to-offscreen copying only.
  53.     NOTE THAT THE PARAMETER maskRgn IS ALMOST NEVER A MASK REGION!  It is passed
  54.     from the drawData field of the graphic record. It should normally be nil, but
  55.     can be used for data required by a specific custom bitcopying procedure.
  56.     
  57.     If the "real" CopyBits is used directly for offscreen-to-offscreen drawing, care must be
  58.     taken that this field is nil or contains a real region handle.
  59. */
  60.  
  61. typedef pascal void (*BitCopyProc) (const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
  62.     const Rect *dstRect, short mode, RgnHandle maskRgn);
  63.     
  64. /*
  65.     Prototype for autochange procedure, which periodically moves graphic,
  66.     changes frames, scrolls graphic, etc.
  67. */
  68.  
  69. typedef pascal void (*AutoChangeProc) (GEWorldPtr world, GrafElPtr element);
  70.  
  71. /*
  72.     Prototype for interact procedure, which handles collisions
  73. */
  74.  
  75. typedef pascal void (*CollisionProc)(GEWorldPtr world, GrafElPtr element, 
  76.                                             GEDirection dir, GrafElPtr hitElement);
  77.     
  78. /*
  79.     Prototype for rendering procedure to draw element into offscreen "stage" world
  80. */
  81.  
  82. typedef pascal void (*RenderProc)(GrafElPtr element, GWorldPtr destGWorld);
  83.  
  84. /*
  85.     Prototype for sensor-tracking procedure, called when mouse button is pressed
  86.     in a graphic element with sensor properties
  87. */
  88.  
  89. typedef pascal Boolean (*SensorTrack)(GEWorldPtr world, GrafElPtr sensor);
  90.  
  91. /*
  92.     Prototype for action procedure to be called by sensor
  93. */
  94.  
  95. typedef pascal void (*SensorAction)(GEWorldPtr world, short sensorState);
  96.  
  97. /*
  98.     Defined values for flags field of Graphic Element. Bits 5-13 are reserved
  99.     for future system use, bits 16-31 are available for use in defining
  100.     custom Graphic Elements.
  101. */
  102.  
  103. enum {    geShown =        0x00000001L,
  104.         geChanged =        0x00000002L,
  105.         geHit =            0x00000004L,
  106.         geSensor =        0x00000008L,
  107.         geForward =        0x00000010L,
  108.         geMirrored =    0x00004000L,
  109.         geInverted =    0x00008000L
  110.     };
  111.     
  112. /*
  113.     The structure of an entry in a world's sensorList
  114. */
  115.  
  116. typedef struct SensorListEntry *SListEntryPtr;
  117.  
  118. typedef struct SensorListEntry {
  119.     SListEntryPtr    nextEntry;
  120.     Rect            sensorRect;
  121.     OSType            sensorID;
  122. } SensorListEntry;
  123.  
  124. /*
  125.     The variable-rate timer for a GEWorld
  126. */
  127.  
  128. //Timer "rate" for 1 ms world time/ms real time
  129. #define geTimerStdRate 0x00010000
  130.  
  131. typedef struct {
  132.     TMTask            aTMTask;
  133.     unsigned long    currentTime;
  134.     long             currentRate;
  135.     long            timeAccum;
  136.     Boolean            running;
  137. } GETMgrRec, *GETMgrRecPtr;
  138.  
  139.  
  140.     
  141. /*
  142.     A basic Graphic Element
  143. */
  144.  
  145. typedef struct GrafElement{
  146.  
  147.     //Bookkeeping and access
  148.     GrafElPtr        nextByPlane;        //Link in world's drawList
  149.     GrafElPtr        nextByID;            //Link in world's idList
  150.     GrafElPtr        masterGrafEl;        //Master (if any) controls movement of this GrafEl
  151.     GrafElPtr        slaveGrafEl;        //This GrafEl controls movement of slave (if any) 
  152.     OSType            objectID;            //This element's "name"
  153.     short            drawPlane;            //"Level" of object, higher number == closer to front
  154.     short            resID;                //# of resource from which element was derived, if any
  155.     long            flags;                //See definitions above
  156.     
  157.     //Basic graphics data
  158.     GWorldPtr        graphWorld;            //Ptr to offscreen graphic, if any
  159.     Rect            graphRect;            //Source rectangle used by RenderProc
  160.     Rect            animationRect;        //Total dest rectangle, GEWorld coordinates
  161.     RenderProc        renderIt;            //Element's rendering procedure
  162.     BitCopyProc        drawIt;                //Lowlevel bit copier, if any
  163.     Ptr                drawData;            //Data passed to drawIt, if any
  164.     Rect            drawRect;            //Rect to update on this cycle
  165.     short            copyMode;            //Bit transfer mode
  166.  
  167.     //For automatic periodic changes
  168.     short            changeIntrvl;        //Interval between automatic changes
  169.     unsigned long    lastChangeTime;        //Last time autochange proc was called
  170.     AutoChangeProc    changeIt;            //Function for automatic changes
  171.     Ptr                changeData;            //Extra data for automatic changes
  172.     
  173.     //For collisions
  174.     CollisionProc    doCollision;        //Proc called when element collides
  175.     short            collisionPlane;        //Collides only with elements on this plane
  176.     
  177.     //For direct user interactions
  178.     short            sensorType;            //Used to distinguish variant types
  179.     SensorTrack        trackingProc;        //Called when mousedown in sensor's rectangle
  180.     SensorAction    actionProc;            //Called by trackingProc when sensor is "activated"
  181.     short            sensorState;        //For whatever a sensor needs to save across calls
  182.  
  183. } GrafElement;
  184.     
  185. /*
  186.     A world of Graphic Elements
  187. */
  188.  
  189. typedef struct GEWorld {
  190.  
  191.     //Objects maintained by this world
  192.     GrafElPtr            drawList;        //Head of linked list of GrafElements in draw order
  193.     GrafElPtr            idList;            //Head of linked list of GrafElements by ID
  194.  
  195.     //Graphic environment of this world
  196.     CWindowPtr            gEWWindow;        //Onscreen window for this world
  197.     GDHandle            windGDevice;    //Device for this window
  198.     GWorldPtr            stageGWorld;    //Offscreen construction "stage" for this world
  199.     Rect                animationRect;    //Total dest rect of this world
  200.     CTabHandle            worldCTable;    //Offscreen color table, should == onscreen cTable
  201.     Point                worldFocus;        //Offset of world from window top left
  202.     
  203.     //Current state of this world
  204.     GraphicLoadFunc        defaultLoader;    //Loader used if no other is specified
  205.     LHeaderPtr            activeRectList;    //Two lists of update rects, so that animation and
  206.     LHeaderPtr            safeRectList;    //screen updating can be concurrent
  207.     LHeaderPtr            sensorList;        //Sensors in this world, see Sensors.h
  208.     GETMgrRec            worldTime;        //Timer record for this world
  209.     unsigned long        lastFrameTime;    //last time screen was updated
  210.     short                msPerFrame;        //minimum "projection" interval, ms
  211.     Boolean                active;            //True if this animation is running
  212.     Boolean                changed;        //True if at least 1 object needs drawing
  213.     
  214. } GEWorld;
  215.  
  216. #endif